
export const chatMsg = async (vm, msg) => {
	const event = msg;
 
	const hasNew = event.data.some((item) => item.sendUserId !== vm.user.userId);
	if (hasNew && vm.isSound===1) {
//	playNotificationSound('msg');
	}

	try {
		let newMessages = [...vm.messages];
		if (event.data.length < 1) {
			return
		}
		event.data.forEach((newMessage) => {
			const existingIndex = newMessages.findIndex((oldMessage) => oldMessage.timestamp ===
				newMessage.timestamp);
			// 直接更新 newMessage 的 content 属性
			newMessage.content = {
				...newMessage.content,
				unsend: false
			};

			if (existingIndex !== -1) {
				// 如果存在相同 timestamp 的消息，更新该消息
				newMessages[existingIndex] = {
					...newMessage
				};
			} else {
				// 如果不存在，添加新消息
				newMessages.push({
					...newMessage
				});
			}
		});
		vm.messages = newMessages.sort((a, b) => a.timestamp - b.timestamp);

	} catch (error) {
		console.error('解析WebSocket消息失败:', error);
	}
	
}
